package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.SubFormPoJo;
import com.xbongbong.pro.enums.CommunicatePlanNotifyTypeEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.business.CommunicatePlanEnum;
import com.xbongbong.saas.enums.dictionary.CommunicatePlanStatusEnum;
import com.xbongbong.saas.enums.dictionary.CommunicatePlanTargetEnum;
import com.xbongbong.saas.enums.dictionary.DelayCaseEnum;
import com.xbongbong.saas.enums.dictionary.IsDelayEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import lombok.Getter;

/**
 * @author long.rao
 * @version v1.0
 * @date 2019/1/17 19:35
 * @since v1.0
 */
@Getter
public enum TempCommunicatePlanEnum {
    //
    BASE_INFO(CommunicatePlanEnum.BASE_INFO),
    NAME(CommunicatePlanEnum.NAME),
    LINK_CUSTOMER(CommunicatePlanEnum.LINK_CUSTOMER),
    EXECUTOR(CommunicatePlanEnum.EXECUTOR),
    EXECUTOR_LINKED_TEXT(CommunicatePlanEnum.EXECUTOR_LINKED_TEXT),
    TARGET(CommunicatePlanEnum.TARGET),
    COMMUNICATE_TIME(CommunicatePlanEnum.COMMUNICATE_TIME),
    MEMO(CommunicatePlanEnum.MEMO),
    NOTIFY_TYPE(CommunicatePlanEnum.NOTIFY_TYPE),
    NOTIFY_TIME(CommunicatePlanEnum.NOTIFY_TIME),

    SYSTEM_INFO(CommunicatePlanEnum.SYSTEM_INFO),
    CREATOR_ID(CommunicatePlanEnum.CREATOR_ID),
    ADD_TIME(CommunicatePlanEnum.ADD_TIME),
    UPDATE_TIME(CommunicatePlanEnum.UPDATE_TIME),

    DELAY_CAUSE(CommunicatePlanEnum.DELAY_CAUSE),
    DELAY_MEMO(CommunicatePlanEnum.DELAY_MEMO),

    IS_DELAY(CommunicatePlanEnum.IS_DELAY),
    ORI_COMMUNICATE_TIME(CommunicatePlanEnum.ORI_COMMUNICATE_TIME),
    CUSTOMER_NAME_LINK_TEXT(CommunicatePlanEnum.CUSTOMER_NAME_LINK_TEXT),
    FINISH_USER_AVATAR(CommunicatePlanEnum.FINISH_USER_AVATAR),
    FINISH_USER_NAME(CommunicatePlanEnum.FINISH_USER_NAME),
    FINISH_USER_ID(CommunicatePlanEnum.FINISH_USER_ID),
    FINISH_TIME(CommunicatePlanEnum.FINISH_TIME),
    STATUS(CommunicatePlanEnum.STATUS),

    CONTACT_WAY(CommunicatePlanEnum.CONTACT_WAY),
    CREATE_TYPE(CommunicatePlanEnum.CREATE_TYPE),;

    private CommunicatePlanEnum anEnum;

    TempCommunicatePlanEnum(CommunicatePlanEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempCommunicatePlanEnum> getAllEnum() {
        List<TempCommunicatePlanEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    /**
     * 初始化名称
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initName(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setNoRepeat(0);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化拜访目的
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initTarget(FieldAttrEntity fieldAttrEntity) {
//        List<ItemPoJo> itemList = new ArrayList<>();
//        for (CommunicatePlanTargetEnum communicatePlanTargetEnum : CommunicatePlanTargetEnum.values()) {
//            ItemPoJo itemPoJo = new ItemPoJo();
//            itemPoJo.setText(communicatePlanTargetEnum.getName());
//            itemPoJo.setValue(communicatePlanTargetEnum.getCode());
//            itemList.add(itemPoJo);
//        }
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(CommunicatePlanTargetEnum.class, fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setDictionaryFlag(1);
    }

    /**
     * 初始化执行人
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initExecutor(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        ItemPoJo itemPoJo1 = new ItemPoJo();
        itemPoJo1.setText("负责人");
        itemPoJo1.setValue("0");
        itemPoJo1.setChecked(true);
        itemPoJos.add(itemPoJo1);
        ItemPoJo itemPoJo2 = new ItemPoJo();
        itemPoJo2.setText("协同人");
        itemPoJo2.setValue("1");
        itemPoJo2.setChecked(false);
        itemPoJos.add(itemPoJo2);
        ItemPoJo itemPoJo3 = new ItemPoJo();
        itemPoJo3.setText("自定义");
        itemPoJo3.setValue("2");
        itemPoJo3.setChecked(false);
        List<String> fieldMap = new ArrayList<>();
        fieldMap.add(EXECUTOR_LINKED_TEXT.anEnum.getAttr());
        itemPoJo3.setFieldMap(fieldMap);
        itemPoJos.add(itemPoJo3);
        fieldAttrEntity.setItems(itemPoJos);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType("custom");
        defaultAttrPoJo.setDefaultValue("");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化执行人
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initExecutorLinkedText(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setMultiple(1);
    }

    public static void initNotifyType(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        ItemPoJo itemPoJo1 = new ItemPoJo();
        itemPoJo1.setText(CommunicatePlanNotifyTypeEnum.NO_NOTIFY.getAlias());
        itemPoJo1.setValue(CommunicatePlanNotifyTypeEnum.NO_NOTIFY.getCode().toString());
        itemPoJo1.setChecked(true);
        itemPoJos.add(itemPoJo1);
        ItemPoJo itemPoJo2 = new ItemPoJo();
        itemPoJo2.setText(CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_QUARTER_HOUR.getAlias());
        itemPoJo2.setValue(CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_QUARTER_HOUR.getCode().toString());
        itemPoJo2.setChecked(false);
        itemPoJos.add(itemPoJo2);
        ItemPoJo itemPoJo3 = new ItemPoJo();
        itemPoJo3.setText(CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_HOUR.getAlias());
        itemPoJo3.setValue(CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_HOUR.getCode().toString());
        itemPoJo3.setChecked(false);
        itemPoJos.add(itemPoJo3);
        ItemPoJo itemPoJo4 = new ItemPoJo();
        itemPoJo4.setText(CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_DAY.getAlias());
        itemPoJo4.setValue(CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_DAY.getCode().toString());
        itemPoJo4.setChecked(false);
        itemPoJos.add(itemPoJo4);
        ItemPoJo itemPoJo5 = new ItemPoJo();
        itemPoJo5.setText(CommunicatePlanNotifyTypeEnum.ADVANCE_THREE_DAY.getAlias());
        itemPoJo5.setValue(CommunicatePlanNotifyTypeEnum.ADVANCE_THREE_DAY.getCode().toString());
        itemPoJo5.setChecked(false);
        itemPoJos.add(itemPoJo5);
        ItemPoJo itemPoJo6 = new ItemPoJo();
        itemPoJo6.setText(CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_WEEK.getAlias());
        itemPoJo6.setValue(CommunicatePlanNotifyTypeEnum.ADVANCE_ONE_WEEK.getCode().toString());
        itemPoJo6.setChecked(false);
        itemPoJos.add(itemPoJo6);
        ItemPoJo itemPoJo7 = new ItemPoJo();
        itemPoJo7.setText(CommunicatePlanNotifyTypeEnum.CUSTOM_TIME.getAlias());
        itemPoJo7.setValue(CommunicatePlanNotifyTypeEnum.CUSTOM_TIME.getCode().toString());
        itemPoJo7.setChecked(false);

        List<String> fieldMap = new ArrayList<>();
        fieldMap.add(NOTIFY_TIME.anEnum.getAttr());
        itemPoJo7.setFieldMap(fieldMap);
        itemPoJos.add(itemPoJo7);
        fieldAttrEntity.setItems(itemPoJos);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType("custom");
        defaultAttrPoJo.setDefaultValue("");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
    }

    /**
     * 初始化执行时间
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initCommunicateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType("yyyy-MM-dd HH:mm");
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化提醒时间
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initNotifyTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType("yyyy-MM-dd HH:mm");
    }

    /**
     * 初始化访客计划完成状态
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initStatus(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(CommunicatePlanStatusEnum.class, fieldAttrEntity.getFieldType(),"alias",null));
    }

    public static void initDelayCause(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(DelayCaseEnum.class, fieldAttrEntity.getFieldType()));
    }

    public static void initIsDelay(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(IsDelayEnum.class, fieldAttrEntity.getFieldType()));
    }


    /**
     * 初始化关联客户
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initLinkCustomer(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CUSTOMER.getCode());
        fieldAttrEntity.setLinkedText(CUSTOMER_NAME_LINK_TEXT.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initContactWay(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity item = InitExplainsHelper.setField(StringConstant.PLAN_CONTACT_ATTR, "联系人", "contact", FieldTypeEnum.TEXT.getType(), 4, ShowTypeEnum.DETAIL.getCode(), 0, 1);
        items.add(item);
        FieldAttrEntity item2 = InitExplainsHelper.setField(StringConstant.PLAN_PHONE_ATTR, "联系方式", "phone", FieldTypeEnum.TEXT.getType(), 4, ShowTypeEnum.DETAIL.getCode(), 0, 1);
        items.add(item2);
        FieldAttrEntity item3 = InitExplainsHelper.setField(StringConstant.PLAN_ADDRESS_ATTR, "地址", "address", FieldTypeEnum.TEXT.getType(), 4, ShowTypeEnum.DETAIL.getCode(), 0, 1);
        items.add(item3);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
}
